package org.fuys.etp.core.pool.factory;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @projectName: fuys-etp-final
 * @package: org.fuys.etp.core.pool.factory
 * @className: NamedThreadPoolFactory
 * @author: WangJing
 * @description: 命名线程池工厂
 * @date: 2025/2/10 21:21
 * @version: 1.0
 */
public class NamedThreadPoolFactory implements ThreadFactory {

    private final String prefix;

    private final AtomicInteger count = new AtomicInteger(1);

    public NamedThreadPoolFactory(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r,prefix+"-"+count.getAndIncrement());
        thread.setDaemon(true);
        return thread;
    }
}
